1. Field of the Invention
The present invention relates to techniques for reducing memory usage in computing devices. More specifically, the present invention relates to a method and an apparatus for reducing memory usage by encoding two values in a single field.
2. Related Art
Many software programs include “strings” which comprise ordered sequences of symbols. Such strings are typically defined as structures in a programming language, and are stored as string objects in a runtime environment associated with the programming language. During program execution, a given program may manipulate these string objects, and also compute and store additional values related to a given string, such as the length of the string and a hash value for the string. In some systems, computing these additional values may not be optional, and re-computing the values may also be difficult (or even impossible). Hence, a system may store such values as part of the string object. For instance, the runtime environment may allocate additional fields for each string to store (and thereby avoid re-computing) such values. However, allocating multiple fields for each string can consume a substantial amount of memory for programs that include a large number of strings. This memory usage can become a problem for memory-constrained computing devices.
Hence, what is needed is a system that facilitates storing strings without the above-described problems.